// smartlogistics/pages/smartLogistics/warehousemanagement/warehousemanagement.js
const _wx = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickname: "",
    show: false,
    showse: false,
    active: 2,
    limit: 10,
    page: 1,
    rankList: [],
    lastPage: 1,
    text: false,
    actions: [],
    // actions: [{
    //     name: '选项1',
    //   },
    //   {
    //     name: '选项2',
    //   },
    //   {
    //     name: '选项3',
    //   },
    // ],
    icon: {
      active: 'https://m.bjclb.cn/assets/tabbar1.png',
      normal: 'https://m.bjclb.cn/assets/tabbar1x.png',
    },
    icon2: {
      active: 'https://m.bjclb.cn/assets/tabbar2.png',
      normal: 'https://m.bjclb.cn/assets/tabbar2x.png',
    },
    icon3: {
      active: 'https://m.bjclb.cn/assets/tabbar3.png',
      normal: 'https://m.bjclb.cn/assets/tabbar3x.png',
    },
    datalist:[],
    ids:"",
    idss:""
  },

  onClose() {
    this.setData({
      show: false
    });
  },

  onSelect(event) {
    console.log(event.detail);
  },
  shows:function(event) {
    this.setData({
      show: true
    })
    // console.log(event.currentTarget.dataset.id,event.currentTarget.dataset.ids);
    this.setData({datalist:event.currentTarget.dataset.ids.split(",")})
    this.setData({ids:event.currentTarget.dataset.id})
    // console.log(this.data.ids);
    this.alladmin()
  },
  onSubmit: function () {
    this.setData({
      show: false
    })
    this.setData({
      nickname: ''
    })
    this.alladmin()
  },
  handlepush: function () {
    wx.redirectTo({
      url: '../../pages/warehousingitems/warehousingitems',
    })
  },
  handlepus: function () {
    wx.redirectTo({
      url: '../../pages/smartLogistics/smartLogistics',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  warehouseSelect() {
    const that = this
    _wx.getData('/admin/warehouse/warehouse/select', 'GET', {
      page: this.data.page,
      limit: this.data.limit
    }, function (res) {
      if (res.code == 0) {
        that.setData({
          rankList: res.data
        })

      } else {
        console.log(res.msg);
      }
    });
  },
  alladmin() {

    const that = this

    _wx.getData('/admin/warehouse/noneedauth/admins', 'GET', {

      nickname: this.data.nickname
    }, function (res) {
      if (res.code == 0) {
        that.setData({
          actions: res.data
        })
        for (let i of res.data) {
          // 处理数据
          i.showse = true;
          for (let n of that.data.datalist) {
            if (Number(i.id) === Number(n)) {
              i.showse = false;
            }
          }
        }
        console.log(that.data.actions);
      } else {
        console.log(res.msg);
      }
    });

  },
  conten(event){
    console.log(event.currentTarget.dataset.item.id);
    console.log(event.currentTarget.dataset.index);
    this.setData({idss:event.currentTarget.dataset.item.id})
    this.data.datalist.push(String(event.currentTarget.dataset.item.id))
  this.data.actions[event.currentTarget.dataset.index].showse = !this.data.actions[event.currentTarget.dataset.index].showse
  this.data.idss = this.data.datalist.join()
  },
  onSearch() {

    this.alladmin()
    this.setData({
      actions: []
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.warehouseSelect()
    this.alladmin()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.lastPage) {
      this.setData({
        text: true
      })
      return false
    }
    this.setData({
      page: this.data.page + 1
    })
    this.warehouseSelect()
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})